package dao;

import model.Folk;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class AddFolkDateBase {
    private String dbdriver="com.mysql.jdbc.Driver";
    private String dburl="jdbc:mysql://localhost:3306/sctu-javaweb-2018?serverTimezone=UTC&characterEncoding=UTF-8";
    private String dbuser="root";
    private String dbpassword="123456";

    public void addFolk(Folk folk)throws Exception{
        Connection connection=null;
        PreparedStatement preparedStatement=null;
        Class.forName(dbdriver);
        connection= DriverManager.getConnection(dburl,dbuser,dbpassword);

        String sql="INSERT INTO folk(username,folk_Name,folk_Image,folk_Introduce,folk_Price,folk_Type,folk_Bed,folk_People,folk_Area)" +
                "VALUES(?,?,?,?,?,?,?,?,?)";
        preparedStatement=connection.prepareStatement(sql);
        preparedStatement.setString(1,folk.getUsername());
        preparedStatement.setString(2,folk.getFolkName());
        preparedStatement.setString(3,folk.getFolkImage());
        preparedStatement.setString(4,folk.getFolkIntroduce());
        preparedStatement.setFloat(5,folk.getFolkPrice());
        preparedStatement.setString(6,folk.getFolkType());
        preparedStatement.setInt(7,folk.getFolkBed());
        preparedStatement.setInt(8,folk.getFolkPeople());
        preparedStatement.setString(9,folk.getFolkArea());
        preparedStatement.execute();
        connection.close();
        preparedStatement.close();

    }
}
